/**
 * 
 */
package com.suyx.job.service.area.impl;

import java.util.HashMap;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.suyx.job.entity.RoleInfo;
import com.suyx.job.entity.TuInfo;
import com.suyx.job.enums.SectEnums;
import com.suyx.job.utils.ScreenCapture;
import com.suyx.job.utils.SysStaticData;

/**
 * @author syx
 *
 */
@Service
public class GoToDhwAreaServiceImpl extends AbstractAreaService{

	public final static Map<String,String> options_x = new HashMap<>();  
	public final static Map<String,String> options_y = new HashMap<>();
	static {  
		options_x.put("0", "784 317");  
		options_x.put("1", "489 245");  
		options_x.put("2", "593 233");
		options_x.put("3", "687 242"); 
		options_x.put("4", "488 316");
		options_x.put("5", "580 341");
		options_x.put("6", "684 335");
		options_x.put("7", "487 415");
		options_x.put("8", "586 429");
		options_x.put("9", "686 419");
		
		options_y.put("0", "936 339");  
		options_y.put("1", "630 225");  
		options_y.put("2", "724 234");
		options_y.put("3", "821 230"); 
		options_y.put("4", "626 327");
		options_y.put("5", "725 330");
		options_y.put("6", "818 330");
		options_y.put("7", "620 430");
		options_y.put("8", "715 430");
		options_y.put("9", "820 430");
	}
	
	@Override
	public boolean execute(String device, String path, String area) {
		try {
			String[] infos = SysStaticData.AL1.get("东海湾").split("&");
			userAL1(device,infos);
			//点击NPC
			ScreenCapture.mouseClick(device, "804 313");
			Thread.sleep(1 * 1000L);
			//到达东海湾
			ScreenCapture.mouseClick(device, "1205 346");
			Thread.sleep(2 * 1000L);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		return false;
	}

	@Override
	public boolean support(String area) {
		return SectEnums.DHW.getCode().equals(area);
	}

	private void input_x(String device,String x){
		for(int i =0;i<x.length();i++){
			char c = x.charAt(i);
			String x_zb = options_x.get(String.valueOf(c));
			ScreenCapture.mouseClick(device, x_zb);
		}
	}
	
	private void input_y(String device,String y){
		for(int i =0;i<y.length();i++){
			char c = y.charAt(i);
			String y_zb = options_y.get(String.valueOf(c));
			ScreenCapture.mouseClick(device, y_zb);
		}
	}

	@Override
	public boolean goToPoint(RoleInfo roleInfo, String path, TuInfo tuInfo) {
		String device = roleInfo.getDevice();
		String area = tuInfo.getZuobiaoX()+" "+tuInfo.getZuobiaoY();
		try {
			Thread.sleep(2 * 1000L);
			
			ScreenCapture.mouseClick(device, "117 68");//打开地图
	        ScreenCapture.mouseClick(device, "494 111");// 选x坐标
	        String x = area.split(" ")[0];
	        String y = area.split(" ")[1];
	        input_x(device,x);
	        ScreenCapture.mouseClick(device, "789 422");
	        ScreenCapture.mouseClick(device, "635 111"); // 选y坐标
	        input_y(device, y);
	        ScreenCapture.mouseClick(device, "912 416");
	        ScreenCapture.mouseClick(device, "771 107");  // 前往
	        ScreenCapture.mouseClick(device, "1053 84"); //关闭地图
	       
	        startGoto(roleInfo,path,tuInfo);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}
	
}
